/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package MODEL.DAO;

import MODEL.POJO.TaiKhoanPOJO;
import MODEL.UTIL.MySqlDataAccessHelper;
import java.sql.ResultSet;
import java.sql.SQLException;

/**
 *
 * @author kijoo
 */
public class TaiKhoanDAO {
      public static TaiKhoanPOJO DangNhap(String tenDangNhap, String matKhau) {
        TaiKhoanPOJO tk= null;
        try {
            String sql = String.format("SELECT * FROM TAIKHOAN WHERE TENTAIKHOAN=BINARY('%s')"
                    + " AND MATKHAU=BINARY(md5('%s'))", tenDangNhap, matKhau);
            MySqlDataAccessHelper helper = new MySqlDataAccessHelper();
            helper.Open();
            ResultSet rs = helper.executeQuery(sql);
            if (rs.next()) {
                tk=new TaiKhoanPOJO();
                tk.setIdtaikhoan(rs.getInt("idtaikhoan"));
                tk.setTentaikhoan(rs.getString("tentaikhoan"));
                tk.setDiachi(rs.getString("diachi"));
                tk.setSodienthoai(rs.getString("sodienthoai"));
                tk.setEmail(rs.getString("email"));
               
            }
            helper.Close();
        } catch (SQLException ex) {
            System.out.println(ex.getMessage());
        }
        return tk;
    }
}
